/*
 * @Author: zhangfeng
 * @Date: 2024-01-23 15:35:09
 * @LastEditTime: 2024-01-23 15:43:58
 * @LastEditors: zhangfeng
 * @Description:
 * @FilePath: \nodeapi\src\utils\index.js
 * © 2023 张峰，All rights reserved.
 */
function getUploadDirName() {
  const date = new Date();
  let month = Number.parseInt(date.getMonth()) + 1;
  month = month.toString().length > 1 ? month : `0${month}`;
  const dir = `${date.getFullYear()}${month}${date.getDate()}`;
  return dir;
}

const path = require("path");
const fs = require("fs");

function checkDirExist(p) {
  if (!fs.existsSync(p)) {
    fs.mkdirSync(p);
  }
}

function getUploadFileExt(name) {
  let ext = name.split(".");
  return ext[ext.length - 1];
}

function getUploadFileName(name) {
  let ext = name.split(".");
  return ext[0];
}

module.exports = {
  getUploadDirName,
  checkDirExist,
  getUploadFileExt,
  getUploadFileName,
};
